﻿using MediatR;
using PublicClass;
using S.Eartag.Domain.Model;
using S.Eartag.Infrastructure.Impl;
using S.Eartag.Infrastructure.Interface;
using S.Eartag.Infrastructure.Migrations;
using S.Eartag.Read.API.Application.Command.MarkedConditionCommand;
using System.Collections.Generic;

namespace S.Eartag.Read.API.Application.CommandHandlers.MarkedConditionCommandHandler
{
    public class MarkedConditionGetEarCommandHandler : IRequestHandler<MarkedConditionGetEarCommand, List<SelectList>>
    {
        private readonly IMarkRepository markRepository;
        private readonly ILamBingRepository lamBingRepository;
        private readonly ISheepFileRepository sheepFileRepository;


        public MarkedConditionGetEarCommandHandler(IMarkRepository markRepository, ILamBingRepository lamBingRepository, ISheepFileRepository sheepFileRepository)
        {
            this.markRepository = markRepository;
            this.lamBingRepository = lamBingRepository;
            this.sheepFileRepository = sheepFileRepository;
        }

        public async Task<List<SelectList>> Handle(MarkedConditionGetEarCommand request, CancellationToken cancellationToken)
        {
            
            var info = lamBingRepository.All().Result.Where(x=>x.IsDel==false);
            List<SelectList> result =new List<SelectList>();
            foreach (var item in info)
            {
                SelectList selectList = new SelectList();
                selectList.Id=item.Id;
                selectList.Name = item.EarNumber;
                result.Add(selectList);
            }
            return result;
        }
    }
}
